﻿<%@ Page Language="C#" AutoEventWireup="true" EnableEventValidation="false" CodeBehind="DocList.aspx.cs" Inherits="EuroAudit.DocList" Culture="lv-LV" %>

<%@ Register assembly="AjaxControlToolkit" namespace="AjaxControlToolkit" tagprefix="cc1" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Dokumentu saraksts</title>
    <script type="text/javascript">
    
      function pageLoad() 
      {
      }
      /*function __doPostBack(eventTarget, eventArgument) {
          document.form1.__EVENTTARGET.value = eventTarget;
          document.form1.__EVENTARGUMENT.value = eventArgument;
          document.form1.submit();
      }*/

      function OpenModal() {
          var MessageSource = "cmdDel";
          var MessageText = "Dokuments tiks dzēsts. Vai turpināt?";
          var WinSettings = "center:yes;resizable:no;dialogHeight:200px;status:no";
          var RetVal = window.showModalDialog("ModalDlg.aspx", MessageText, WinSettings);
              //__doPostBack("cmdDelLn", "");
              //__doPostBack("cmdDel","");
          //$get('cmdDel').click();
          if (document.getElementById("_RESULT").textContent != "undefined")
              document.getElementById("_RESULT").textContent = RetVal + MessageSource;
          if (document.getElementById("_RESULT").innerText != "undefined")
              document.getElementById("_RESULT").innerText = RetVal + MessageSource;          
          //document.getElementById('_RESULT').innerText = RetVal + MessageSource;
          __doPostBack('_RESULT', '');
              //document.getElementById('cmdDelH').click();

      }
      function overlay() {
          xyz = document.getElementById("overlay");
          xyz.style.visibility = (xyz.style.visibility == "visible") ? "hidden" : "visible";

      }

        
    function GetFileName(val)
    {   
        var i = val.lastIndexOf("\\");
        var sFN=val.substring(i+1);
        //SplitFileName(sFN);
        return sFN;
    }
    function SplitFileName(value)
    {
        var sSplit=value.split("_");
        document.form1.txtDocDate.Value=sSplit[0]//datums
        document.form1.txtDocNum.Value=sSplit[1]//dok. numurs
        document.form1.txtOrgID.Value=sSplit[2]//klienta kods
        document.form1.ddlDocType.Value=sSplit[3]//dok. tips
        return;
    }
    function cmdDelH_onclick() {
        
    }

    </script>
    <script runat="server">
      [System.Web.Services.WebMethod]
      static public string SplitFileName2Date(string contextKey)
      {
          try
          {
              DateTime rDate;
              string[] rStr = contextKey.Split('_');
              rDate = DateTime.ParseExact(rStr[0].ToString().Insert(2, ".").Insert(5, "."), "dd.MM.yyyy", System.Globalization.CultureInfo.InvariantCulture);
              return rDate.ToString("dd.MM.yyyy");
          }
          catch (Exception ex)
          {
              return "";
          }
      }
      [System.Web.Services.WebMethod]
      static public string SplitFileName2Number(string contextKey)
      {
          try
          {
              string[] rStr = contextKey.Split('_');
              return rStr[1];
          }
          catch (Exception ex)
          {
              return "";
          }
          
      }
      [System.Web.Services.WebMethod]
      static public string SplitFileName2OrgID(string contextKey)
      {
          try
          {
              string[] rStr = contextKey.Split('_');
              return rStr[2];
          }
          catch (Exception ex)
          {
              return "";
          }
      }
      [System.Web.Services.WebMethod]
      static public string SplitFileName2DocType(string contextKey)
      {
          try
          {
              string[] rStr = contextKey.Split('_');
              return rStr[3].Remove(rStr[3].LastIndexOf('.'));
          }
          catch (Exception ex)
          {
              return "";
          }
      }
      
    </script>

    <link href="Style.css" rel="stylesheet" type="text/css" />
    <style type="text/css">
        .style1
        {
            width: 156px;
        }
    </style>
</head>
<body class="PageMain">
    <form id="form1" runat="server" enctype="multipart/form-data">
    <input type ="hidden" name ="__EVENTTARGET" value ="">
    <input type ="hidden" name ="__EVENTARGUMENT" value ="">
    <div id="overlay">
        <div align="center">
            <asp:Label ID="lblDelDoc" runat="server" CssClass="LabelFieldCaption" Text="Dokuments tiks dzēsts. Vai turpināt?"></asp:Label>
            <br />
            <asp:Button ID="cmdDelOKDoc" runat="server" CssClass="cmdDel" OnClientClick="overlay()"
                OnClick="cmdDel_Click" Text="OK" />
            <asp:Button ID="cmdDelCancel" runat="server" CssClass="cmdClose" OnClientClick="overlay()"
                Text="Cancel" />
        </div>
    </div>
    <div align="center">
        <asp:Label ID="lblOrgCap" runat="server" CssClass="LabelPageCaption" 
            Text="Klients"></asp:Label>
        <br />
        <asp:Label ID="lblCaption" runat="server" CssClass="LabelFieldCaption" 
            Text="dokumentu saraksts"></asp:Label>
        <br />
        <asp:Label ID="lblOrgID" runat="server" Visible="False"></asp:Label>
        <br />
        <asp:ScriptManager ID="ScriptManager1" runat="server" />
    </div>
    <asp:Button ID="cmdNew" runat="server" CssClass="cmdNew" 
        Text="Jauns dokuments" onclick="cmdNew_Click" />
    <br />
        <asp:UpdatePanel ID="upFile" runat="server" 
            UpdateMode="Conditional">
            <ContentTemplate>
                <asp:Panel ID="pFile" runat="server" Visible="False">
                    <asp:Label ID="Label7" runat="server" CssClass="LabelFieldCaption" 
                        Text="Faila nosaukums"></asp:Label>
                    <a name="pEdit"></a>
                    <br />
                    <asp:FileUpload ID="fuFile" runat="server" CssClass="FieldsText" 
                        onchange="this.form.txtDocName.value=GetFileName(this.value);$find('txtDocNum_DPE').populate(GetFileName(this.value));$find('txtDocDate_DPE').populate(GetFileName(this.value));$find('ddlDocType_DPE').populate(GetFileName(this.value));" />
                </asp:Panel>
            </ContentTemplate>
            <Triggers>
                <asp:AsyncPostBackTrigger ControlID="cmdNew" EventName="Click" />
                <asp:PostBackTrigger ControlID="cmdSave" />
            </Triggers>
        </asp:UpdatePanel>
    <asp:UpdatePanel ID="upEdit" runat="server">
        <ContentTemplate>
            <asp:Panel ID="pEdit" runat="server" CssClass="PanelEdit" Height="697px" 
                Visible="False">
                <asp:TextBox ID="txtDocID" runat="server" CssClass="FieldsUnvisible"></asp:TextBox>
                <br />
                <asp:Label ID="Label8" runat="server" CssClass="LabelFieldCaption" 
                    Text="Organizācijas kods"></asp:Label>
                <br />
                <asp:TextBox ID="txtOrgID" runat="server" CssClass="FieldsText" 
                    ontextchanged="txtOrgID_TextChanged"></asp:TextBox>
                <br />
                <asp:Label ID="Label1" runat="server" CssClass="LabelFieldCaption" 
                    Text="Dokumenta tips"></asp:Label>
                <br />
                <cc1:DynamicPopulateExtender ID="ddlDocType_DPE" runat="server" Enabled="True" 
                    PopulateTriggerControlID="" ServiceMethod="SplitFileName2DocType" 
                    TargetControlID="txtDocType">
                </cc1:DynamicPopulateExtender>
                <asp:TextBox ID="txtDocType" runat="server"></asp:TextBox>
                <cc1:DropDownExtender ID="txtDocType_DDE" runat="server" 
                    DropDownControlID="pDocType" DynamicServicePath="" Enabled="True" 
                    TargetControlID="txtDocType">
                </cc1:DropDownExtender>
                <br />
                <asp:Panel ID="pDocType" runat="server">
                    <asp:ListBox ID="lbDocType" runat="server" AutoPostBack="True" 
                        onselectedindexchanged="lbDocType_SelectedIndexChanged"></asp:ListBox>
                </asp:Panel>
                <br />
                <asp:Label ID="Label2" runat="server" CssClass="LabelFieldCaption" 
                    Text="Dokumenta numurs"></asp:Label>
                <br />
                <asp:TextBox ID="txtDocNum" runat="server" CssClass="FieldsText"></asp:TextBox>
                <cc1:DynamicPopulateExtender ID="txtDocNum_DynamicPopulateExtender" 
                    runat="server" Enabled="True" 
                    TargetControlID="txtDocNum" 
                    ServiceMethod="SplitFileName2Number" BehaviorID="txtDocNum_DPE">
                </cc1:DynamicPopulateExtender>
                <br />
                <asp:Label ID="Label3" runat="server" CssClass="LabelFieldCaption" 
                    Text="Dokumenta datums"></asp:Label>
                <br />
                <asp:TextBox ID="txtDocDate" runat="server" CssClass="FieldsText"></asp:TextBox>
                <cc1:DynamicPopulateExtender ID="txtDocDate_DPE" runat="server" Enabled="True" 
                    PopulateTriggerControlID="" ServiceMethod="SplitFileName2Date" 
                    TargetControlID="txtDocDate">
                </cc1:DynamicPopulateExtender>
                <asp:Button ID="cmdDocDate" runat="server" CssClass="cmdShowLists" Text="..." 
                    onclick="cmdDocDate_Click" />
                <br />
                <asp:Calendar ID="cDocDate" runat="server" FirstDayOfWeek="Monday" 
                    Visible="False" onselectionchanged="cDocDate_SelectionChanged">
                    <TodayDayStyle BackColor="Red" />
                </asp:Calendar>
                <asp:Label ID="Label6" runat="server" CssClass="LabelFieldCaption" 
                    Text="Dokumenta nosaukums"></asp:Label>
                <br />
                <asp:TextBox ID="txtDocName" runat="server" CssClass="FieldsText" 
                    ontextchanged="txtDocName_TextChanged1"></asp:TextBox>
                <br />
                <asp:Label ID="Label4" runat="server" CssClass="LabelFieldCaption" 
                    Text="Piezīmes"></asp:Label>
                <br />
                <asp:TextBox ID="txtDocDescr" runat="server" CssClass="FieldsText"></asp:TextBox>
                <br />
                <asp:Label ID="Label5" runat="server" CssClass="LabelFieldCaption" 
                    Text="Unikāla saite piekļuvei bez autorizācijas"></asp:Label>
                &nbsp;
                <asp:Label ID="lblDocPath" runat="server" CssClass="LabelFieldCaption"></asp:Label>
                <br />
                <asp:TextBox ID="txtLink" runat="server" CssClass="FieldsText"></asp:TextBox>
                <asp:Button ID="cmdLink" runat="server" CssClass="cmdShowLists" 
                    onclick="cmdLink_Click" Text="..." />
                <br />
                <br />
                <asp:CheckBox ID="chMail" runat="server" CssClass="CheckBox" 
                    Text="Nosūtīt paziņojumu klientam" 
                    oncheckedchanged="chMail_CheckedChanged" AutoPostBack="True" />
                <br />
                <div align="center">
                    <asp:Label ID="lblErr" runat="server" CssClass="LabelError"></asp:Label>
                    <br />
                    <asp:Button ID="cmdSave" runat="server" CssClass="cmdSave" Text="Saglabāt" 
                        onclick="cmdSave_Click" />
                    &nbsp;<asp:Button ID="cmdDel" runat="server" CssClass="cmdDel" Text="Dzēst" 
                        onclick="cmdDel_Click" Visible="False" />
                    &nbsp;<asp:Button ID="cmdDelMod" runat="server" CssClass="cmdDel" 
                        onclientclick="overlay()" Text="Dzēst" />
                    <asp:Button ID="cmdClose" runat="server" CssClass="cmdClose" 
                        onclick="cmdClose_Click" Text="Aizvērt" />
                    &nbsp;
                    <br />
                    <asp:TextBox ID="_RESULT" runat="server" CssClass="FieldsUnvisible"></asp:TextBox>
                    <br />
                    
                </div>
            </asp:Panel>
            <br />
            <asp:UpdatePanel ID="upList" runat="server" UpdateMode="Conditional">
                <ContentTemplate>
                    <asp:Panel ID="pTabs" runat="server">
                    </asp:Panel>
                    <br />
                    <table style="width:100%;">
                        <tr>
                            <td class="style1" valign="top" width="20%">
                                <asp:Table ID="tCmd" runat="server" Width="95%">
                                </asp:Table>
                            </td>
                            <td width="80%">
                                <asp:Table ID="tDocs" runat="server" CssClass="TableList" GridLines="Both">
                                </asp:Table>
                            </td>
                        </tr>
                    </table>
                    <br />
                    
                </ContentTemplate>
            </asp:UpdatePanel>
        </ContentTemplate>
        <Triggers>
            <asp:AsyncPostBackTrigger ControlID="cmdNew" EventName="Click" />
        </Triggers>
    </asp:UpdatePanel>
    </form>
</body>
</html>
